package com.fh.controller.system.timer;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.fh.controller.collection.Collection;
import com.fh.controller.system.tools.SmsUtil;
import com.fh.service.building.bill.BillService;
import com.fh.util.DateUtil;
import com.fh.util.PageData;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

import java.util.List;

/**
 * Created by caozengling on 2017/10/31.
 */
@DisallowConcurrentExecution
public class TimerCharge implements Job {

    private BillService billService = (BillService)ApplicationContextUtil.getBean("billService");

    @Override
    public void execute(JobExecutionContext context) {
        this.findMsgBill();
        this.findChargeBill();
    }

    private void findMsgBill() {
        try {
            PageData pd = new PageData();
            pd.put("PAY_DATE", DateUtil.getAfterDayDate("-3"));
            List<PageData> list = billService.findMsgAndChargeBill(pd);
            System.out.println("*** 今日发送提醒账单，数量：" + list.size() + " ***");
            if (list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO 发送短信提醒
                    String tel=list.get(i).getString("TX_TEL");
                    String price=list.get(i).getString("TOTAL_PRICE");
                    System.out.println("+++++++++++++++++++++++++");
//                    SmsUtil.sendSms(tel,price);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void findChargeBill() {
        try {
            PageData pd = new PageData();
            pd.put("PAY_DATE", DateUtil.getDay());
            List<PageData> list = billService.findMsgAndChargeBill(pd);
            System.out.println("*** 今日代收应收账单，数量：" + list.size() + " ***");
            if (list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    // TODO 自动扣款
                    System.out.println("----- 第" + (i + 1) + "条账单信息 -----");
                    System.out.println(list.get(i));
                    Collection tp = new Collection();
                    tp.TestPayReq(list.get(i));
                    System.out.println("--------------------------------------");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}